package com.isnotlocus.gulimail.product.service.impl;

import com.isnotlocus.gulimail.product.entity.AttrEntity;
import com.isnotlocus.gulimail.product.service.AttrService;
import com.isnotlocus.gulimail.product.vo.AttrRelationVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.isnotlocus.common.utils.PageUtils;
import com.isnotlocus.common.utils.Query;

import com.isnotlocus.gulimail.product.dao.AttrAttrgroupRelationDao;
import com.isnotlocus.gulimail.product.entity.AttrAttrgroupRelationEntity;
import com.isnotlocus.gulimail.product.service.AttrAttrgroupRelationService;


@Service()
public class AttrAttrgroupRelationServiceImpl extends ServiceImpl<AttrAttrgroupRelationDao, AttrAttrgroupRelationEntity> implements AttrAttrgroupRelationService {

    @Autowired
    AttrService attrService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<AttrAttrgroupRelationEntity> page = this.page(
                new Query<AttrAttrgroupRelationEntity>().getPage(params),
                new QueryWrapper<AttrAttrgroupRelationEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public boolean saveBatchs(List<AttrRelationVo> attrRelationVo) {
        boolean b=false;
        if (attrRelationVo != null) {
            List<AttrAttrgroupRelationEntity> list = attrRelationVo.stream().map((item) -> {
                AttrAttrgroupRelationEntity attrAttrgroupRelationEntity = attrAttrgroupRelationEntity = new AttrAttrgroupRelationEntity();
                BeanUtils.copyProperties(item, attrAttrgroupRelationEntity);
                return attrAttrgroupRelationEntity;
            }).collect(Collectors.toList());

           b = this.saveBatch(list);
        }

        return b;
    }


}